/* GUI CONVERTED from rsitq.p (converter v1.75) Sat Aug 12 23:14:17 2000 */
/* rsitq.p - Release Management Supplier Schedules                      */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                   */
/* REVISION: 7.3    LAST MODIFIED: 12/06/93           BY: WUG *GH75*    */
/* REVISION: 7.3    LAST MODIFIED: 01/31/94           BY: WUG *GI56*    */
/* REVISION: 7.3    LAST MODIFIED: 02/24/94           BY: WUG *GI86*    */
/* REVISION: 7.4    LAST MODIFIED: 11/01/94           BY: ame *GN88*    */
/* REVISION: 9.0    LAST MODIFIED: 03/29/99           BY: *J3BM* Reetu Kapoor */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00           BY: *N0KP* myb          */


/* DETERMINE "IN TRANSIT" QUANTITY FOR A PO LINE ITEM.  THIS IS
THE QUANTITY THAT EXISTS FOR THE PO LINE IN ALL UNCONFIRMED SHIPPERS. */

/*J3BM*/ /** TO IMPROVE PERFORMANCE   **/

{mfdeclre.i}

define input  parameter order         as character.
define input  parameter line          as integer.
define output parameter intransit_qty as decimal.

/*J3BM** def new shared workfile work_abs_mstr like abs_mstr.  */
define variable already_rcvd_this_shipper as decimal.
define variable to_receive_this_shipper   as decimal.

/*J3BM*/ {rcwabsdf.i new}

         intransit_qty = 0.

/*J3BM** find po_mstr where po_nbr = order no-lock. */
/*J3BM*/ for first po_mstr
/*J3BM*/    fields (po_nbr po_vend)
/*J3BM*/    where po_nbr = order no-lock:
/*J3BM*/ end. /* FOR FIRST PO_MSTR */



/*GI86 IF THE SHIPPER IS CONFIRMED WE IGNORE IT, SINCE THAT MEANS
IT  IS  NO LONGER "IN TRANSIT".  OTHERWISE, IT MAY BE POSSIBLE WE
RECEIVED AGAINST THE SAME SHIPPER USING POPORC.P, SO WE  NEED  TO
REDUCE  THE  IN-TRANSIT  TOTAL  BY  THE QUANTITIES IN THE RECEIPT
HISTORY.  WE PRESUME THE SHIPPER ID AND THE PACKING SLIP ARE  THE
SAME.*/

/*J3BM** for each abs_mstr no-lock       */
/*J3BM*/ for each abs_mstr
/*J3BM*/    fields (abs_id abs_shipfrom abs_status abs_type) no-lock
            where abs_shipfrom = po_vend
            and   abs_id begins "s"
            and   abs_type     = "r"
            and   substr(abs_status,2,1) <> "y":
/*GUI*/ if global-beam-me-up then undo, leave.

/*GN88* for each work_abs_mstr:*/
/*GN88*/    for each work_abs_mstr exclusive-lock:
               delete work_abs_mstr.
            end.

            {gprun.i ""rcsoisa.p"" "(input recid(abs_mstr))"}
/*GUI*/ if global-beam-me-up then undo, leave.


            to_receive_this_shipper = 0.

            for each work_abs_mstr no-lock
               where work_abs_mstr.abs_order = order                /*GI56*/
               and integer(work_abs_mstr.abs_line) = line,              /*GI56*/
/*J3BM**  each pod_det no-lock            */
/*J3BM*/       each pod_det
/*J3BM*/       fields (pod_line pod_nbr pod_part pod_um_conv) no-lock
               where pod_nbr  = work_abs_mstr.abs_order
               and   pod_line = integer(work_abs_mstr.abs_line):
                  to_receive_this_shipper = to_receive_this_shipper
           + (work_abs_mstr.abs_qty - work_abs_mstr.abs_ship_qty) / pod_um_conv.
            end.


   /*GI86 SEE WHAT WE'VE ALREADY RECEIVED ON THIS SHIPPER*/

/*J3BM**  find pod_det where pod_nbr = order and pod_line = line no-lock.  */
/*J3BM*/    for first pod_det
/*J3BM*/       fields (pod_line pod_nbr pod_part pod_um_conv)
/*J3BM*/       where pod_nbr  = order
/*J3BM*/       and   pod_line = line no-lock:
/*J3BM*/    end.
/*GUI*/ if global-beam-me-up then undo, leave.
 /* FOR FIRST POD_DET */

            already_rcvd_this_shipper = 0.

/*J3BM**    for each prh_hist no-lock  */
/*J3BM*/    for each prh_hist
/*J3BM*/       fields (prh_line prh_nbr prh_part prh_ps_nbr prh_rcvd prh_vend)
/*J3BM*/       no-lock
               where prh_vend   = po_vend
               and   prh_ps_nbr = substr(abs_id,2)
/*J3BM**       and   prh_nbr    = order               */
               and   prh_part   = pod_part
/*J3BM*/       and   prh_nbr    = order
               and   prh_line   = line:
               already_rcvd_this_shipper = already_rcvd_this_shipper + prh_rcvd.
            end.

            intransit_qty = intransit_qty
                + max(0, to_receive_this_shipper - already_rcvd_this_shipper).
         end.
